<template>
	<view class="flex flex-col h-screen">
		<NavBarVue title="牌阵"></NavBarVue>
		<view class="flex-1 overflow-hidden bg-white rounded-lg">
			<scroll-view scroll-y="true" class="h-full">
				<view class="p-30">
					<view class="">
						<sendSettingVue :isCard="false" :isView="false"></sendSettingVue>
					</view>
					<view class="flex justify-center items-center mt-20">
						<text class="text-sm font-bold mr-10">您本次需要支付</text>
						<ImageBoxVue :src="postFrom.paysts==0?'/static/icons/blue.png':'/static/icons/red.png'" width="28rpx"
							height="28rpx">
						</ImageBoxVue>
						<view class="text-sm font-bold ml-10">
							<text v-if="postFrom.sec == 1"> {{postFrom.sinpay}}*{{postFrom.pret}}+12 =
								{{postFrom.sinpay * postFrom.pret * 1 + 12}}</text>
							<text v-else> {{postFrom.sinpay}}*{{postFrom.pret}} = {{postFrom.sinpay * postFrom.pret * 1}}</text>
							<text class="ml-10">颗{{postFrom.paysts==0?'蓝钻':'红钻'}}</text>
						</view>
					</view>
					<view class="my-20">
						<button class="rounded-full" type="primary"
							@click="onPlay">确认支付{{payPrice}}颗{{postFrom.paysts==0?'蓝钻':'红钻'}}</button>
					</view>
					<AgreementPlatformVue v-model="isAgree"></AgreementPlatformVue>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		computed,
		provide,
	} from 'vue';
	import {
		onShow,
		onLoad
	} from "@dcloudio/uni-app"
	import sendSettingVue from "../tabbar/components/community/sendSetting.vue"
	import AgreementPlatformVue from "../login/components/AgreementPlatform.vue"
	import communityApi from '@/apis/apiList/communityApi';
	const pretList = [{
		text: "1位",
		value: 1
	}, {
		text: "3位",
		value: 3
	}, {
		text: "5位",
		value: 5
	}, ]
	const postFrom = ref({
		paysts: 0, //支付方式
		sinpay: "", //支付金额
		prv: 0, //私有
		pret: 0, //解读人数
		sec: 0, //保密
		exp: 0, //游客讲解 
		obs: 0, //评论
		sdes: 1, // 是否有牌阵信息，0否 1是
		"deck.id": '', // 牌阵ID
		describe: "", //描述
		ppst: 2, // 帖子类型 0 普通贴 1定向贴 2 快速贴
	})
	const posts = ref(3) // 板块判断
	const isAgree = ref(false)
	const systemSetting = ref([{
		name: 'PsychologicalBlueFees',
		kbidc: 1
	}, {
		name: 'PsychologicalRedFees',
		kbidc: 1
	}])
	provide('posts', posts)
	provide('postFrom', postFrom)
	provide('pretList', pretList)
	provide('systemSetting', systemSetting)

	const payPrice = computed(() => {
		if (postFrom.value.sec == 1) {
			return postFrom.value.sinpay * postFrom.value.pret * 1 + 12
		} else {
			return postFrom.value.sinpay * postFrom.value.pret * 1
		}
	})
	onLoad((option) => {
		postFrom.value['deck.id'] = option.id
		postFrom.value.describe = option.ask
		systemSetting.value[0].kbidc = option.blue
		systemSetting.value[1].kbidc = option.red
	})
	const onPlay = () => {
		if (!isAgree.value) {
			uni.showToast({
				icon: "none",
				title: "请同意平台规则！"
			})
			return
		}
		const params = {
			"member.id": uni.getStorageSync('user').id,
			"bbsplate.id": '1321849359872032768',
			...postFrom.value
		}
		// if (posts.value == 1) { // 心理
		// 	params.addparme = postFrom.value.addparme.splice(",")
		// }
		// if (posts.value == 2) { // 星图
		// 	params.selcard = postFrom.value.selcard
		// 	params.starsts = postFrom.value.starsts
		// }
		// if (posts.value == 3) { // 卡牌
		// 	params['deck.id'] = postFrom.value.addparme.splice(",")
		// 	params.selcard = postFrom.value.addparme.splice(",")
		// }
		delete params.member
		console.log(params)
		communityApi.generatePoss(params).then(res => {
			uni.showToast({
				icon: "none",
				title: '测试成功'
			})
			setTimeout(() => {
				uni.navigateTo({
					url: `/pages/test/quickDetails?id=${res.data.id}`
				})
			}, 1000)
		})
	}
</script>

<style>
</style>